package flc.ast.adapter;

import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

import flc.ast.R;
import flc.ast.utils.AppSpUtils;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.bean.StkResBean;

public class CaricatureAdapter extends StkProviderMultiAdapter<StkResBean> {

    public CaricatureAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new CaricatureProvider());
    }

    private class CaricatureProvider extends BaseItemProvider<StkResBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_caricature;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, StkResBean bean) {
            Glide.with(getContext()).load(bean.getThumbUrl())
                    .into((ImageView) baseViewHolder.getView(R.id.ivCaricatureItemImg));
            baseViewHolder.setText(R.id.tvCaricatureItemName, bean.getName());
            baseViewHolder.setText(R.id.tvCaricatureItemDesc, bean.getDesc());

            String tag = "";
            for (String s : bean.getTagNameList()) {
                tag += s + "/";
            }
            baseViewHolder.setText(R.id.tvCaricatureItemType, tag);
            bean.setSelected(false);
            List<StkResBean> listSp = AppSpUtils.getCollectList();
            if (listSp != null && listSp.size() > 0) {
                for (StkResBean stkResBean : listSp) {
                    if (stkResBean.getThumbUrl().equals(bean.getThumbUrl())) {
                        bean.setSelected(true);
                        break;
                    }
                }
            }
            if (bean.isSelected()) {
                baseViewHolder.setImageResource(R.id.ivCaricatureItemCollect, R.drawable.ycx);
            } else {
                baseViewHolder.setImageResource(R.id.ivCaricatureItemCollect, R.drawable.wxc);
            }
        }
    }

}
